package com.boat.framework.base.api;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 第三方系统返回结果
 * 
 * @author 周江
 *
 * @param <T>
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class TrdResponse<T> {
	/**
	 * 是否调用成功
	 */
	private Boolean success;
	/**
	 * 接口返回响应码
	 */
	private String respCode;
	/**
	 * 接口返回消息
	 */
	private String respMsg;
	/**
	 * 第三方响应结果
	 */
	private T data;

	public TrdResponse<T> failed(String respCode,String respMsg) {
		TrdResponse<T> trdResponse = new TrdResponse<>();
		trdResponse.setSuccess(false).setRespCode(respCode).setRespMsg(respMsg);
		return trdResponse;
	}

	public TrdResponse<T> success(T data,String respCode,String respMsg) {
		TrdResponse<T> trdResponse = new TrdResponse<>();
		trdResponse.setSuccess(true).setRespCode(respCode).setRespMsg(respMsg).setData(data);
		return trdResponse;
	}

	public TrdResponse<T> success(T data) {
		TrdResponse<T> trdResponse = new TrdResponse<>();
		trdResponse.setSuccess(true).setData(data);
		return trdResponse;
	}

	public TrdResponse<Void> success(Boolean isSuccess,String respCode,String respMsg) {
		TrdResponse<Void> trdResponse = new TrdResponse<>();
		trdResponse.setSuccess(isSuccess).setRespCode(respCode).setRespMsg(respMsg);
		return trdResponse;
	}

	public boolean isSuccess() {
		return success;
	}

}
